package com.xue566.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.xue566.dao.StudentMapper;
import com.xue566.entity.StudentEntity;
import com.xue566.enums.StateEnum;
import com.xue566.service.IStudentService;
import com.xue566.util.ResultBody;
import com.xue566.util.StateException;
import org.apache.commons.lang.StringUtils;
import org.springframework.stereotype.Service;


/**
 * @Author: Wuzh
 * @Description:
 * @Date Created in 11:35 2020/8/23
 * @return
 */
@Service
public class StudentServiceImpl extends ServiceImpl<StudentMapper, StudentEntity> implements IStudentService {

    /**
     * @Author: Wuzh
     * @Description: 根据条件查询学生对象
     * @Data:
     */
    @Override
    public ResultBody<StudentEntity> queryList (StudentEntity studentEntity) {
        Page<StudentEntity> page = new Page<>(studentEntity.getPageNum(), studentEntity.getPageSize());
        QueryWrapper<StudentEntity> queryWrapper = new QueryWrapper<>();
        if (null == studentEntity.getTrackId() || "".equals(studentEntity.getTrackId())) {
            throw new StateException(StateEnum.TRACK_NULL_EXCE);
        }
        if (StringUtils.isNotBlank(studentEntity.getStuId())) {
            queryWrapper.eq("stuId", studentEntity.getStuId());
        }
        if (studentEntity.getStarLevel() != 0) {
            queryWrapper.eq("starLevel", studentEntity.getStarLevel());
        }
        if (StringUtils.isNotBlank(studentEntity.getStuName())) {
            queryWrapper.eq("stuName", studentEntity.getStuName());
        }
        if (StringUtils.isNotBlank(studentEntity.getStuSex())) {
            queryWrapper.eq("stuSex", studentEntity.getStuSex());
        }
        if (StringUtils.isNotBlank(studentEntity.getStuMobile())) {
            queryWrapper.eq("stuMobile", studentEntity.getStuMobile());
        }
        if (StringUtils.isNotBlank(studentEntity.getStuSchool())) {
            queryWrapper.eq("stuSchool", studentEntity.getStuSchool());
        }
        if (StringUtils.isNotBlank(studentEntity.getStuGrade())) {
            queryWrapper.eq("stuGrade", studentEntity.getStuGrade());
        }
        if (studentEntity.getIntention() != 0) {
            queryWrapper.eq("intention", studentEntity.getIntention());
        }
        if (StringUtils.isNotBlank(studentEntity.getCenterId())) {
            queryWrapper.eq("centerId", studentEntity.getCenterId());
        }
        if (StringUtils.isNotBlank(studentEntity.getSourceId())) {
            queryWrapper.eq("sourceId", studentEntity.getSourceId());
        }
        if (StringUtils.isNotBlank(studentEntity.getIntroduceEmpId())) {
            queryWrapper.eq("introduceEmpId", studentEntity.getIntroduceEmpId());
        }
        if (StringUtils.isNotBlank(studentEntity.getIntroduceId())) {
            queryWrapper.eq("introduceId", studentEntity.getIntroduceId());
        }
        if (StringUtils.isNotBlank(studentEntity.getInfoLink())) {
            queryWrapper.eq("infoLink", studentEntity.getInfoLink());
        }
        if (StringUtils.isNotBlank(studentEntity.getKeyWord())) {
            queryWrapper.eq("keyWord", studentEntity.getKeyWord());
        }
        if (StringUtils.isNotBlank(studentEntity.getStuAddress())) {
            queryWrapper.eq("stuAddress", studentEntity.getStuAddress());
        }
        if (StringUtils.isNotBlank(studentEntity.getInfoCondition())) {
            queryWrapper.eq("infoCondition", studentEntity.getInfoCondition());
        }
        if (StringUtils.isNotBlank(studentEntity.getAllotTime())) {
            queryWrapper.eq("allotTime", studentEntity.getAllotTime());
        }
        if (StringUtils.isNotBlank(studentEntity.getAllotManId())) {
            queryWrapper.eq("allotManId", studentEntity.getAllotManId());
        }
        if (StringUtils.isNotBlank(studentEntity.getStuRemark())) {
            queryWrapper.eq("stuRemark", studentEntity.getStuRemark());
        }
        if (studentEntity.getState() != 0) {
            queryWrapper.eq("state", studentEntity.getState());
        }
        if (StringUtils.isNotBlank(studentEntity.getStuRemark())) {
            queryWrapper.eq("stuRemark", studentEntity.getStuRemark());
        }
        if (studentEntity.getIsFullPay() != 0) {
            queryWrapper.eq("isFullPay", studentEntity.getStuRemark());
        }
        if (StringUtils.isNotBlank(studentEntity.getUserId())) {
            queryWrapper.eq("userId", studentEntity.getUserId());
        }
        if (StringUtils.isNotBlank(studentEntity.getCreateTime())) {
            queryWrapper.eq("createTime", studentEntity.getCreateTime());
        }
        if (StringUtils.isNotBlank(studentEntity.getOperatorTime())) {
            queryWrapper.eq("operatorTime", studentEntity.getOperatorTime());
        }
        if (studentEntity.getIsPublic() != 0) {
            queryWrapper.eq("isPublic", studentEntity.getIsPublic());
        }
        if (studentEntity.getIsUsed() != 0) {
            queryWrapper.eq("isUsed", studentEntity.getIsUsed());
        }
        IPage<StudentEntity> pageResult = baseMapper.selectPage(page, queryWrapper);
        return ResultBody.success(studentEntity.getPageNum(), studentEntity.getPageSize(), pageResult.getTotal(), pageResult.getRecords(), "/student");
    }


    /**
     * @Author: Wuzh
     * @Description: 查询一条学生记录
     * @Data:
     */
    public ResultBody<StudentEntity> selectStudent (StudentEntity studentEntity) {
        if (studentEntity == null) {
            throw new StateException(StateEnum.REQUEST_PARAM_EXCE);
        }
        if ("".equals(studentEntity.getTrackId()) || null == studentEntity.getTrackId()) {
            throw new StateException(StateEnum.TRACK_NULL_EXCE);
        }
        return null;
    }


    /**
     * @Author: Wuzh
     * @Description: 修改学生记录信息
     * @Data:
     */
    public ResultBody<StudentEntity> updateStudent (StudentEntity studentEntity) {
        if (studentEntity == null) {
            throw new StateException(StateEnum.REQUEST_PARAM_EXCE);
        }
        if ("".equals(studentEntity.getTrackId()) || null == studentEntity.getTrackId()) {
            throw new StateException(StateEnum.TRACK_NULL_EXCE);
        }
        return null;
    }


    /**
     * @Author: Wuzh
     * @Description: 删除一条学生记录
     * @Data:
     */
    public ResultBody<StudentEntity> deleteStudent (StudentEntity studentEntity) {
        if (studentEntity == null) {
            throw new StateException(StateEnum.REQUEST_PARAM_EXCE);
        }
        if ("".equals(studentEntity.getTrackId()) || null == studentEntity.getTrackId()) {
            throw new StateException(StateEnum.TRACK_NULL_EXCE);
        }
        return null;
    }


}
